package lew.bing.novels;

import java.io.Closeable;
import java.io.IOException;
import java.util.List;

/**
 * Created by 刘国兵 on 2019/8/18.
 *
 * @author 刘国兵
 */
public class WriteNovels {

    private CollectNovels collectNovels;
    private NovelWriter novelWriter;


    public WriteNovels(CollectNovels collectNovels, NovelWriter novelWriter) {
        this.collectNovels = collectNovels;
        this.novelWriter = novelWriter;
    }

    public void write() throws IOException {
        List<Novel> collect = collectNovels.collect();
        try {
            for (Novel novel : collect) {
                novelWriter.write(novel);
            }
        } finally {
            novelWriter.close();
        }
    }

    public static void main(String[] args) throws IOException {
        DefaultCollectNovels collectNovels = new DefaultCollectNovels(new H88DUSHUNovelLoader("https://www.88dush.com/xiaoshuo/1/1236/"));
        NovelWriter writer;
//        writer = new EpubWriter("雪洗天下", "醉虎");
//        writer = new TxtWriter("./", "雪洗天下", false, 700);
        writer = new PdfWriter("雪洗天下","醉虎", "雪洗天下.pdf");
        new WriteNovels(collectNovels, writer).write();
    }

}
